package com.gy.education;

import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.gy.education.utils.MainTabEnum;

public class MainActivity  extends BaseActivity {
    //定义FragmentTabHost对象
    private FragmentTabHost mTabHost;
    //定义一个布局
    private LayoutInflater layoutInflater;
    private MainTabEnum[] mainTabArray = new MainTabEnum[]{MainTabEnum.HOME,MainTabEnum.TABLE,MainTabEnum.DEVELOP,MainTabEnum.LIFE,MainTabEnum.MINE};

    @Override
    protected void initView() {
        setContentViewRes(R.layout.activity_main);
        hidenTop();
    }

    @Override
    protected void initData() {
        //实例化布局对象
        layoutInflater = LayoutInflater.from(this);

        //实例化TabHost对象，得到TabHost
        mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
        mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

        //得到fragment的个数
        int count = mainTabArray.length;

        for(int i = 0; i < count; i++){
            //为每一个Tab按钮设置图标、文字和内容
            TabHost.TabSpec tabSpec = mTabHost.newTabSpec(mainTabArray[i].name).setIndicator(getTabItemView(i));
            //将Tab按钮添加进Tab选项卡中
            mTabHost.addTab(tabSpec, mainTabArray[i].mClass, null);
            //设置Tab按钮的背景
            //            mTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.selector_tab_background);
        }
    }

    @Override
    protected void setListener() {
        super.setListener();
//        WifiAdmin wifiAdmin = new WifiAdmin(this);
//        wifiAdmin.openWifi();
//        wifiAdmin.addNetwork(wifiAdmin.CreateWifiInfo("moutaiclub3", "12345+Ad", 3));
    }

    /**
     * 给Tab按钮设置图标和文字
     */
    private View getTabItemView(int index){
        View view = layoutInflater.inflate(R.layout.tab_item_view, null);

        ImageView imageView = (ImageView) view.findViewById(R.id.imageview);
        imageView.setImageResource(mainTabArray[index].imgId);

        TextView textView = (TextView) view.findViewById(R.id.textview);
        textView.setText(mainTabArray[index].name);

        return view;
    }
}

